#coding=utf-8

import multiprocessing
import threading
import time

def foo(i):
    while i>0:
        i -=1


if __name__ =='__main1__':
    for i in range(10):
        p = multiprocessing.Process(target=foo, args=(100000000,))
        p.start()

manage = multiprocessing.Manager()
dict = manage.dict()
def foo2(i):
    dict[i] = 100+i
    print dict.values()

if __name__ =='__main2__':
     for i in xrange(2):
         p = multiprocessing.Process(target=foo2, args=(i,))
         p.start()
         p.join()


import time

def foo3(i):
    time.sleep(2)
    return i+100

def bar(arg):
    print arg

pool = multiprocessing.Pool(5)

if __name__=='__main__':
    print pool.apply(foo3,(1,))
    print pool.apply_async(func=foo3, args=(1,)).get()

    for i in xrange(10):
        pool.apply_async(func=foo3, args=(i,), callback=bar)

    print 'end'
    pool.close()
    pool.join()